################################################################################
# Created By:Pietryka
# Creation Date:  2016-08-22
# Purpose: Impute missing data for CPS Turnout
# Questions: mpietryka@fsu.edu
################################################################################


# PREAMBLE =============================================



# LOAD PACKAGES  -----------------------------

library(foreign)
library(dplyr)
library(readr)

# Load Data ----------------------------


# load objects: 'cps_sub_10', 'cps_sub_14', 'main_vars', and 'covariates'
# created in 'CPS-1A-Clean-Turnout.R'
load("Data/CPS-1A-Clean-Turnout.Rdata")


# Classify variables ============================================



# variables to treat as categorical
categorical_covariates <- c("PEMARITL", "PTDTRACE", "PEMLR")


# IMPUTE DATA  -------------------

library("Amelia")

set.seed(4564)

n_imputations <- 20

amelia_10 <- amelia(cps_sub_10,
                    m = n_imputations,
                    noms = c(main_vars, categorical_covariates))

impute_10 <- amelia_10$imputations[1:n_imputations]

amelia_14 <- amelia(cps_sub_14,
                    m = n_imputations,
                    noms = c(main_vars, categorical_covariates))

impute_14 <- amelia_14$imputations[1:n_imputations]

#  Save =====================================

save.image("Data/CPS-2A-Impute-Turnout.RData")
